//
//  IconView.m
//  微博2期
//
//  Created by J on 15/12/5.
//
//

#import "IconView.h"
#import "User.h"
#import "UIImageView+WebCache.h"

@interface IconView ()
@property(nonatomic,weak)UIImageView * verifiedView;



@end
@implementation IconView

- (UIImageView *)verifiedView{
    
    if (_verifiedView) {
        
        UIImageView * verifiedView =[UIImageView new];
        [self addSubview:verifiedView];
        self.verifiedView =verifiedView;
    }
    
    return _verifiedView;
    
}


//更换图片
- (void)setUser:(User *)user{
    _user = user;
    
    //1.下载图片
    [self sd_setImageWithURL:[NSURL URLWithString:user.profile_image_url] placeholderImage:[UIImage imageNamed:@"avatar_default_small"]];
    
    //2.设置加V图片
    self.hidden = NO;
    switch (user.verified_type) {
            case UserVerified_typePersonal://个人认证
        {
            self.verifiedView.image = [UIImage imageNamed:@"avatar_vip"];
        }
            break;
            
        case UserVerified_typeEnterprice://企业认证 三种情况
        case UserVerified_typeOrgMedia:
        case UserVerified_typeOrgWebsite:
        {
            self.verifiedView.image = [UIImage imageNamed:@"avatar_enterprise_vip"];
            
        }
            break;
            
        case UserVerified_typeDaren://达人
        {
            self.verifiedView.image = [UIImage imageNamed:@"avatar_grassroot"];
        }
            break;

        default:
            self.hidden = YES;//没有任何认证

            break;
    }
    
    
}
- (void)layoutSubviews{
    
    [super layoutSubviews];
    self.verifiedView.size = self.verifiedView.image.size;
    self.verifiedView.x = self.width - self.verifiedView.width*0.6;
    self.verifiedView.y = self.height - self.verifiedView.height*0.6;

}


@end
